package com.shopping.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class HelloController {

    @GetMapping(value = "/hello")
    public Map<String, Object> hello(){
        Map<String, Object> map = new HashMap<>();
        map.put("hello", "Hello World!");
        return map;
    }

    @PostMapping(value = "/testJson")
    public Map<String, Object> testJson(@RequestBody JSONObject jsonStr){
        Map<String, Object> map = new HashMap<>();
        System.out.println("jsonStr: " + jsonStr.toString());
        System.out.println("title: " + jsonStr.getString("title"));
        System.out.println("keywords: " + jsonStr.getString("keywords"));
        System.out.println("json: " + jsonStr.getString("json"));
        map.put("jsonStr", jsonStr.toString());
        return map;
    }

}
